package cn.juforg.gravitysnake;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
/**
 *
 * @author Juforg
 *
 */
public class SnakeStartAty extends Activity {
	static char RESTARTGAME = 'r';
	static char CONTINUEGAME = 'c';
	public static final char exitFlag = 'e';
	public static final char aboutFlag = 'a';
	private Button restartGameBtn = null;
	private Button continueBtn = null;
	private Button exitBtn = null;
	private Button aboutBtn = null;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.start);
		restartGameBtn = (Button) findViewById(R.id.restart);
		restartGameBtn.setOnClickListener(new ButtonListener(RESTARTGAME));
		continueBtn = (Button) findViewById(R.id.continuegame);
		continueBtn.setOnClickListener(new ButtonListener(CONTINUEGAME));
		exitBtn = (Button) findViewById(R.id.exitbtn);
		exitBtn.setOnClickListener(new ButtonListener('e'));
		aboutBtn = (Button) findViewById(R.id.aboutbtn);
		aboutBtn.setOnClickListener(new ButtonListener('a'));
		this.setTheme(BIND_NOT_FOREGROUND);
	}
	
	class ButtonListener implements OnClickListener{
		private char flag;
		Intent intent = new Intent();// 生成Intent对象
		
		public ButtonListener(char flag) {
			super();
			this.flag = flag;
		}

		@Override
		public void onClick(View v) {
			if (flag != exitFlag) {
				if (flag==aboutFlag) {
					
				}else if (flag==RESTARTGAME) {
					intent.putExtra("gameMode", SnakeStartAty.RESTARTGAME);
				}else if (flag==CONTINUEGAME) {
					intent.putExtra("gameMode", CONTINUEGAME);
				}
				intent.setClass(SnakeStartAty.this, SnakeMainAty.class);
				SnakeStartAty.this.startActivity(intent);
			}else{
				finish();
			}
		}
		
	}
	
	
	@Override
	protected void onDestroy() {
		System.out.println(" onDestroy");
		super.onDestroy();
	}

	@Override
	protected void onPause() {
		System.out.println("SnakeStart onPause");
//		this.finishFromChild(getParent());	//由子窗口调用finish（）方法关闭
		super.onPause();
	}

	@Override
	protected void onRestart() {
		System.out.println("SnakeStart onRestart");
		super.onRestart();
	}

	@Override
	protected void onResume() {
		System.out.println("SnakeStart onResume");
		super.onResume();
	}

	@Override
	protected void onStart() {
		System.out.println("SnakeStart onStart");
		super.onStart();
	}

	@Override
	protected void onStop() {
		System.out.println("SnakeStart onStop");
		super.onStop();
	}
    
    
}
